home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Headers / mach / hppa / simple_lock.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-15  |  1.6 KB  |  89 lines

  1. /* Copyright (c) 1993 NeXT Computer, Inc.  All rights reserved.
  2.  * 
  3.  *    File:    mach/hppa/simple_lock.h
  4.  *
  5.  *    This file contains machine dependent code for exclusion
  6.  *    lock handling on HPPA-based products.
  7.  *
  8.  * HISTORY
  9.  * 2-July-1993  Mac Gillon at NeXT
  10.  *    Created.
  11.  */
  12.  
  13. #import <mach/hppa/boolean.h>
  14.  
  15. #ifndef    _MACH_HPPA_SIMPLE_LOCK_
  16. #define _MACH_HPPA_SIMPLE_LOCK_
  17.  
  18. struct slock{
  19.     volatile unsigned int lock_data[4];/* in general 1 bit is sufficient */
  20. };
  21.  
  22. typedef struct slock    simple_lock_data_t;
  23. typedef struct slock    *simple_lock_t;
  24.  
  25. extern simple_lock_t    simple_lock_alloc(void);
  26. extern void        simple_lock_free(simple_lock_t);
  27.  
  28. #if    !defined(DEFINE_SIMPLE_LOCK_PRIMS)
  29. static __inline__
  30. #endif
  31. void
  32. simple_lock_init(
  33.     simple_lock_t    slock
  34. )
  35. {
  36.     *((volatile int *)(((int)(slock) + 0x0c) & ~0x0f))  = 1;
  37. }
  38.  
  39. #if    !defined(DEFINE_SIMPLE_LOCK_PRIMS)
  40. static __inline__
  41. #endif
  42. void
  43. simple_unlock(
  44.     simple_lock_t    slock
  45. )
  46. {
  47.     *((volatile int *)(((int)(slock) + 0x0c) & ~0x0f))  = 1;
  48. }
  49.  
  50. #if    !defined(DEFINE_SIMPLE_LOCK_PRIMS)
  51. static __inline__
  52. #endif
  53. boolean_t
  54. simple_lock_try(
  55.     simple_lock_t    slock
  56. )
  57. {
  58.     boolean_t        result;
  59.     volatile int   *lock_word;
  60.     
  61.     lock_word = (volatile int *)(((int)(slock) + 0x0c) & ~0x0f);
  62.     
  63.     asm volatile (
  64.         "ldcws 0(%1),%0"
  65.         : "=r" (result): "r" (lock_word));
  66.     
  67.     return (result);
  68. }
  69.  
  70.  
  71.  
  72. #if    !defined(DEFINE_SIMPLE_LOCK_PRIMS)
  73. static __inline__
  74. #endif
  75. void
  76. simple_lock(
  77.     simple_lock_t    slock
  78. )
  79. {    
  80.     do
  81.         {
  82.         while (*((volatile int *)(((int)(slock) + 0x0c) & ~0x0f))  == 0)
  83.         continue;
  84.     }
  85.     while (!simple_lock_try(slock));
  86. }
  87.  
  88. #endif    _MACH_HPPA_SIMPLE_LOCK_
  89.